package com.pktechan.manage.sendMiniMessage;

import com.alibaba.fastjson.JSONObject;
import com.pktechan.manage.activeMq.ActiveMQSendService;
import com.pktechan.manage.dao.MiniSubscribeMsgMapper;
import com.pktechan.manage.dao.MiniSubscribeMsgParamMapper;
import com.pktechan.manage.sendMiniMessage.bean.BaseMiniMessage;
import com.pktechan.manage.sendMiniMessage.bean.FactoryDeliveryCompleteMessage;
import com.pktechan.manage.sendMiniMessage.bean.MiniSubscribeMessage;
import com.pktechan.manage.sendMiniMessage.bean.MiniSubscribeMessageParam;
import com.pktechan.manage.sendMiniMessage.enumration.SendMiniMessageEnum;
import com.pktechan.manage.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: gsPrivateSale19
 * @description: 厂家接收-配送商-完成配送-配送完成通知
 * @author: qx.zhang
 * @create: 2020-06-01 16:55
 */
@Component("factoryDeliveryCompleteStrategy")
public class FactoryDeliveryCompleteStrategy extends BaseSendMiniMessage implements SendMiniMessageStrategy {

    private static final Logger logger = LoggerFactory.getLogger(FactoryDeliveryCompleteStrategy.class);

//    @Autowired
//    private ActiveMQSendService activeMQSendService;
//
//    @Autowired
//    private MiniSubscribeMsgMapper miniSubscribeMsgMapper;
//    @Autowired
//    private MiniSubscribeMsgParamMapper miniSubscribeMsgParamMapper;

    /**
     * 获取发送消息对象对应的枚举
     *
     * @return
     */
    @Override
    public SendMiniMessageEnum getMappingEnum() {
        return SendMiniMessageEnum.FACTORY_DELIVERY_COMPLETE;
    }

    /**
     * 发送通知消息 ，此方法直接调用企业微信发送消息，网络延迟，故将需发送的消息推送到MQ中
     *
     * @param messageText
     */
    @Override
    public void sendMiniMessage(String messageText) {
//        logger.info("发送厂家接收-配送商-完成配送-配送完成通知消息" + JSONObject.toJSONString(messageText));
//        FactoryDeliveryCompleteMessage factoryDeliveryCompleteMessage = JSONObject.parseObject(messageText, FactoryDeliveryCompleteMessage.class);
//        Integer msgId = SendMiniMessageEnum.FACTORY_DELIVERY_COMPLETE.getId();
//        MiniSubscribeMessage miniSubscribeMessage = miniSubscribeMsgMapper.getById(msgId);
//        List<MiniSubscribeMessageParam> miniSubscribeMessageParamList = miniSubscribeMsgParamMapper.getListByMiniId(msgId);
//        for (MiniSubscribeMessageParam miniSubscribeMessageParam : miniSubscribeMessageParamList) {
//            switch (miniSubscribeMessageParam.getName()) {
//                case "character_string8":
//                    miniSubscribeMessageParam.setValue(String.valueOf(factoryDeliveryCompleteMessage.getTradeOrderId()));
//                    break;
//                case "thing10":
//                    miniSubscribeMessageParam.setValue(factoryDeliveryCompleteMessage.getAddress());
//                    break;
//                case "thing3":
//                    miniSubscribeMessageParam.setValue(factoryDeliveryCompleteMessage.getProductName());
//                    break;
//                case "name4":
//                    miniSubscribeMessageParam.setValue(StringUtil.getChineseLetter(factoryDeliveryCompleteMessage.getDistributionName()));
//                    break;
//            }
//        }
//        miniSubscribeMessage.setToUser(factoryDeliveryCompleteMessage.getOpenId());
//        miniSubscribeMessage.setMiniSubscribeMessageParamList(miniSubscribeMessageParamList);
//        logger.info("发送厂家接收-配送商-完成配送-配送完成通知消息处理后" + JSONObject.toJSONString(miniSubscribeMessage));
//        super.sendSubscribeMessage(miniSubscribeMessage);
    }

    /**
     * 发送微信通知消息请求到中，
     *
     * @param baseMiniMessage
     */
    @Override
    public void sendMiniMessageToActiveMq(BaseMiniMessage baseMiniMessage) {
//        baseMiniMessage.setMessageType(SendMiniMessageEnum.FACTORY_DELIVERY_COMPLETE.getId());
//        logger.debug("发送厂家接收-配送商-完成配送-配送完成通知消息到MQ中" + JSONObject.toJSONString(baseMiniMessage));
//        activeMQSendService.sendMiniMessageQueue(JSONObject.toJSONString(baseMiniMessage));
    }
}
